package com.sgb.kjwl.view.ui.activity.self.lease;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityLeaseOrderSuccessBinding;
import com.sgb.kjwl.di.machine.DaggerMachineComponent;
import com.sgb.kjwl.di.machine.MachineModule;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.WebEvent;
import com.sgb.kjwl.view.ui.activity.lease.LeaseHallActivity2;
import com.sgb.kjwl.viewmodel.house.LeaseOrderSuccessModel;
import com.swgk.core.base.di.AppComponent;

import org.greenrobot.eventbus.EventBus;

import javax.inject.Inject;

public class LeaseOrderSuccessActivity extends AppActivity {

    @Inject
    LeaseOrderSuccessModel viewModel;
    private ActivityLeaseOrderSuccessBinding binding;
    private String id,orderType;
    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMachineComponent.builder().appComponent(appComponent)
                .machineModule(new MachineModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context, String id, String orderType) {
        Intent intent = new Intent(context, LeaseOrderSuccessActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("id", id);
        bundle.putString("orderType", orderType);
        intent.putExtras(bundle);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    /**
     *
     */
    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(LeaseOrderSuccessActivity.this, R.layout.activity_lease_order_success);
//        binding.setViewModel(viewModel);

    }

    @Override
    protected void init() {
        id = getIntent().getStringExtra("id");
        orderType = getIntent().getStringExtra("orderType");
        binding.topLayout.ivBack.setOnClickListener(v -> onBackPressed());
        binding.topLayout.titleView.setText("下单成功");
        binding.tvList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                LeaseHallActivity2.start(LeaseOrderSuccessActivity.this);
            }
        });
        binding.tvOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewModel.getH5Url(id, "1",orderType);
            }
        });
    }

    @Override
    public void onBackPressed() {
        EventBus.getDefault().postSticky(WebEvent.make().setMessageTag(EventConstant.EVENT_WEBVIEW_RELOAD));
        super.onBackPressed();
    }
}
